package org.kjtc.controller;

import org.kjtc.entity.ChargingStation;
import org.kjtc.service.ChargingStationService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dell on 2018/12/10.
 */
@Controller
public class ChargingStationController {

    DateFormat mediumDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM);

    private static Logger logger = Logger.getLogger(ChargingStationController.class);
    @Autowired
    private ChargingStationService chargingStationService;

    @RequestMapping("/chargingStation")
    public String chargingStationPage(){
        return "chargingStation";
    }

    @RequestMapping("/chargingStationStatus")
    public String chargingStationStatePage(){
        return "chargingStationStatus";
    }

    @RequestMapping("/getChargingStationList")
    @ResponseBody
    public Object getChargingStationList(ChargingStation chargingStation) {

        List<Object> list = new ArrayList<Object>();
        try {
            List<ChargingStation> chargingStationNameList = chargingStationService.getChargingStationList(chargingStation);
            for (ChargingStation chargingStationTemp : chargingStationNameList) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("chargingStationID", chargingStationTemp.getChargingStationID());
                map.put("chargingStationName", chargingStationTemp.getChargingStationName());
                map.put("equipmentCount", chargingStationTemp.getEquipmentCount());
                map.put("businessId", chargingStationTemp.getBusinessID());
                map.put("address", chargingStationTemp.getAddress());
                map.put("constructStatus", chargingStationTemp.getConstructStatus());
                map.put("updateDTTM", mediumDateFormat.format(chargingStationTemp.getUpdateDTTM()));
                list.add(map);
            }
        } catch (Exception e) {
            logger.error("下拉列表-充电站名称查询异常:" + e.getMessage());
        }
        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("list", list);
        return map1;
    }

    @RequestMapping("/collectionSettings")
    public String collectionSettingsPage(){
        return "collectionSettings";
    }
    @RequestMapping("/operatorSettings")
    public String operatorSettingsPage(){
        return "operatorSettings";
    }

}
